package com.itfitness.application.winnlistdemo;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * @ProjectName: WinnListDemo
 * @Package: com.itfitness.application.winnlistdemo
 * @ClassName: MyAdapter
 * @Description: java类作用描述 ：适配器
 * @Author: 作者名：lml
 * @CreateDate: 2019/1/24 16:06
 * @UpdateUser: 更新者：
 * @UpdateDate: 2019/1/24 16:06
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>{
    private List<WinnListBean> mDatas;
    private Context mContext;

    public MyAdapter(List<WinnListBean> mDatas, Context mContext) {
        this.mDatas = mDatas;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_winnlist,null,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        WinnListBean winnListBean = mDatas.get(i % mDatas.size());//获取重复数据
        myViewHolder.itemWinnlistTvPhone.setText(winnListBean.getPhone());
        myViewHolder.itemWinnlistTvPrize.setText(winnListBean.getPrize());
    }
    @Override
    public int getItemCount() {
//        本案例一页最多显示6条数据，因此设置如果数据数量大于6等于6才开始滚动
        if(mDatas.size()>5){
//            展示无限数据
            return Integer.MAX_VALUE;
        }else {
            return mDatas.size();
        }
    }
    static class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView itemWinnlistTvPhone;
        private TextView itemWinnlistTvPrize;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            itemWinnlistTvPhone = (TextView) itemView.findViewById(R.id.item_winnlist_tv_phone);
            itemWinnlistTvPrize = (TextView) itemView.findViewById(R.id.item_winnlist_tv_prize);
        }
    }
}
